package org.example.aaaatest;

import com.alibaba.csp.ahas.switchcenter.util.StringUtils;
import com.taobao.csp.switchcenter.core.SwitchManager;
import org.example.aaaatest.Switch01.CommonTypeSwitch;
import org.example.aaaatest.Thread.Worker;
import org.example.aaaatest.a1.BodLanguageText;
import org.example.aaaatest.a1.aaa;
import org.example.aaaatest.a2.BaseResultCode;
import org.example.aaaatest.a2.Result;
import org.example.aaaatest.a2.ResultCode;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.time.Instant;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.Map;
import java.util.concurrent.CountDownLatch;

@SpringBootTest
class AaaaTestApplicationTests11 {

    @Autowired
    private BodLanguageText bodLanguageText;

    @Test
    void contextLoads() {
        System.out.println("bodLanguageText = " + bodLanguageText);
        bodLanguageText.aaa();
    }

    @Test
    void test() {

        Date date = new Date();
        System.out.println("date = " + date);


        // 获取当前时间的Instant对象
        Instant now = Instant.now();
        System.out.println("now = " + now);

        Date from = Date.from(now);
        System.out.println("from = " + from);


        // 将Instant对象转换为UTC时区的DateTime对象
        DateTimeFormatter formatter11 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").withZone(ZoneOffset.UTC);

        // 格式化时间为字符串
        String utcTime = formatter11.format(now);

        System.out.println("UTC时间 = " + utcTime);

        // 将Instant对象转换为北京时间的ZonedDateTime对象
        ZonedDateTime beijingDateTime = now.atZone(ZoneId.of("Asia/Shanghai"));

        // 定义时间格式
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

        // 格式化时间为字符串
        String beijingTime = beijingDateTime.format(formatter);

        System.out.println("北京时间 = " + beijingTime);

        /**
         * date = Wed Feb 26 10:46:51 CST 2025
         * now = 2025-02-26T02:46:51.689Z
         * from = Wed Feb 26 10:46:51 CST 2025
         * UTC时间 = 2025-02-26 02:46:51
         * 北京时间 = 2025-02-26 10:46:51
         */

    }

    @Test
    public void test1() {
        System.out.println("bodLanguageText = " + bodLanguageText);
        SwitchManager.init("app", CommonTypeSwitch.class);
    }

    @Test
    void test2() throws InterruptedException {
        System.out.println("test2");
        int numberOfThreads = 5;
        CountDownLatch latch = new CountDownLatch(numberOfThreads);

        for (int i = 0; i < numberOfThreads; i++) {
            new Thread(new Worker(latch), "Thread-" + (i + 1)).start();
        }

        // 主线程等待所有工作线程完成
        latch.await();
        System.out.println("所有工作线程已完成任务！");
    }

    @Test
    void test3() {
        System.out.println("test3");
        aaa aaa = new aaa();
        aaa.parseJson();
        System.out.println(" =================== ");
        aaa.aa();
    }

    @Test
    void test4() {
        System.out.println("test4 🌛🌛");
        String errorMsg ="";
        System.out.println("errorMsg = " + errorMsg);
        String errorMsg1 =null;
        System.out.println("errorMsg1 = " + errorMsg1);

        Result<ResultCode> result1 = Result.success(ResultCode.create("5-0003", "推动状态失败"));
        System.out.println("result1 = " + result1);
        String sss ="";
        System.out.println("result1.isSuccess() = " + result1.isSuccess());

    }

    @Test
    void test5() {
        System.out.println("test5 🌛🌛");
        int  w =17 *72;
        String num = "张三";
        String num3 = "12345";

        int  w1 =17 *72 /42;
        try {
            System.out.println("test5 ===== "+ w);
            System.out.println("test5 ===== "+ w1);
            System.out.println("test5 ===== "+ num.length());
            System.out.println("test3 ===== "+ num3.length());
            long l = System.currentTimeMillis();
            System.out.println("l = " + l);
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {

        }

    }

    @Test
    void test6() {
        System.out.println("test6 🌛🌛");
        Map<Integer, String> outAccounts = new java.util.HashMap<>();
        outAccounts.put(1, "张三");
        outAccounts.put(4, null);
        outAccounts.put(3, "王五");
        Map<Integer, String> outAccounts1 = new java.util.HashMap<>();
        String accountName = StringUtils.defaultIfEmpty(outAccounts.get(2), "");
        if (StringUtils.isNotEmpty(accountName)) {
            System.out.println("accountNam111111111111111e = " + accountName);
        }
        System.out.println("accountName = " + accountName);
        System.out.println("outAccounts.get(222222222222222222222) = " + outAccounts.get(2));

        String str1 = null;
        String str2 = "Hello, World!";
        String defaultStr = "Default Value";

        System.out.println(StringUtils.defaultIfEmpty(str1, defaultStr)); // 输出: Default Value
        System.out.println(StringUtils.defaultIfEmpty(str2, defaultStr)); // 输出: Hello, World!


    }



}
